<template>
  <div class="container">
    <a-card title="周报告" :bordered="false" class="card-area">
      <a-table
        :loading="loading"
        :columns="columns"
        :data-source="data"
        style="margin-top: 10px"
        :rowKey="
          (record, index) => {
            return index
          }
        "
        bordered
        :pagination="ipagination"
        @change="handleTableChange"
      >
        <template slot="publishStatus" slot-scope="text, record">
          <a-badge :status="record.publishStatus == 0 ? 'warning' : 'success'" />
          {{ text }}
        </template>
        <template slot="operation" slot-scope="text, record">
          <a-button type="primary" @click="viewWeekReport(record)"> 查看报告 </a-button>
        </template>
      </a-table>
    </a-card>
  </div>
</template>
<script>
import { postAction, getAction, deleteAction } from '@/api/manage'

import { PAGE_MENU_TYPE } from '@/store/mutation-types'

const columns = [
  {
    title: '序号',
    dataIndex: 'index',
    align: 'center',
    width: 130
  },
  {
    title: '报告名称',
    dataIndex: 'reportName',
    align: 'center'
  },
  {
    title: '状态',
    dataIndex: 'publishStatusText',
    align: 'center',
    scopedSlots: { customRender: 'publishStatus' }
  },
  {
    title: '报告时间',
    dataIndex: 'reportCreateTime',
    align: 'center'
  },
  {
    title: '发布时间',
    dataIndex: 'publishTime',
    align: 'center'
  },
  {
    title: '操作',
    width: 300,
    align: 'center',
    dataIndex: 'operation',
    scopedSlots: { customRender: 'operation' }
  }
]

export default {
  name: 'Week',
  data() {
    return {
      loading: true,
      data: [],
      columns,
      form: this.$form.createForm(this),
      url: {
        getWeekList: 'patient/report/page'
      },
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      }
    }
  },
  created() {
    this.getWeekList()
  },
  methods: {
    getWeekList() {
      this.data = []
      let params = {
        pageNum: this.ipagination.current,
        pageSize: this.ipagination.pageSize,
        patientId: this.$route.query[PAGE_MENU_TYPE.PatientId],
        type: 2
      }
      postAction(this.url.getWeekList, params)
        .then(res => {
          if (res.success) {
            this.data = res.result.recordList.map((v, i) => {
              return {
                ...v,
                index: i + 1
              }
            })
            this.ipagination.total = res.result.count
          }
        })
        .finally(_ => {
          this.loading = false
        })
    },
    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      console.log(pagination)
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = 'ascend' == sorter.order ? 'asc' : 'desc'
      }
      this.ipagination = pagination
      this.getWeekList()
    },
    viewWeekReport(record) {
      const patientId = this.$route.query[PAGE_MENU_TYPE.PatientId]
      let query = {}
      query[PAGE_MENU_TYPE.ParamsField] = PAGE_MENU_TYPE.HealthManage
      query[PAGE_MENU_TYPE.PatientId] = patientId
      query.reportId = record.dataId
      this.$router.push({
        path: '/report/view',
        query
      })
    }
  }
}
</script>
<style lang="less" scoped></style>

